// pages/teacher/teacherClass/teacherClass.js
var app = getApp();
import {post} from "../../../../asserts/js/request";
import {teacher_active} from "../../../../asserts/js/common/barList";
import {initCourseInit, getCourseParam} from "../../../../asserts/js/common/shareFun";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    top: app.globalData.bottom + 'px',
    barList: teacher_active(0),
    buttom_title: {
      title1: '舞种',
      title2: '课程类型'
    },
    class_list: [],
    tabObj: {},
    alter_show: false,
    className: "",
    danceKind: [],
    courseLevel: [],
    courseNature: [],
    teacherHead: "",
    teacherName: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    var obj = initCourseInit(app.globalData.enum_courseTypes, app.globalData.enum_courseKinds, app.globalData.enum_courseNature)
    this.setData({
      tabObj: obj,
      teacherHead: app.globalData.teacherInfo.teacherPhoto,
      teacherName: app.globalData.teacherInfo.teacherName
    })
    this.getData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  selectBoxShow: function(){
    this.setData({
      alter_show: true
    })
  },
  alterCancel: function() {
    this.setData({
      alter_show: false
    })
  },
  showClassCourse:function(e){
    wx.navigateTo({
      url: '/pages/teacher/myclass/teacherCourseList/teacherCourseList?id=' + e.currentTarget.dataset.item.classId
    })
  },
  showClassStudent:function(e){
    wx.navigateTo({
      url: '/pages/teacher/myclass/teacherClassStudent/teacherClassStudent?classId=' 
      + e.currentTarget.dataset.item.classId
      + '&className='+ e.currentTarget.dataset.item.className
    })
  },
  click: function(e) {
    wx.navigateTo({
      url: '/pages/teacher/myclass/teacherStu/teacherStu?id=' + e.currentTarget.dataset.item.classId
    })
  },
  getData: function() {
    post("queryClass",{
      teacherId: app.globalData.teacherInfo.teacherId,
      orgId: app.globalData.teacherInfo.orgId,
      className: this.data.className,
      danceKind: this.data.danceKind.join("|"),
      courseKind: this.data.courseLevel.join("|"),
      courseNature: this.data.courseNature.join("|")
    }).then(data => {
      console.log("获取教师的班级");
      console.log(data);
      this.setData({
        class_list: data.classInfo
      })
    }).catch(err=>{
      console.log(err)
    })
  },
  selectSure: function(e) {
    let this_ = this;
    var paramList = getCourseParam(e.detail.tabList);
    this.setData({
      danceKind: paramList.danceKind,
      courseLevel: paramList.courseLevel,
      courseNature: paramList.courseNature,
      alter_show: false
    }, function(){
      this_.getData()
    })
  },
  nameChange: function(e) {
    this.setData({
      className: e.detail.value
    })
  }
})